<?php 
$this->lang->load('admin_help', $this->session->admin_language);
$this->load->view('admin/layout/head', array('title'=>$this->lang->line('help'),'css'=>array('/assets/umeditor/themes/default/css/umeditor.min.css')), FALSE);
?>

<div id="container">
<ul class="nav nav-tabs" id="subject-tab">
	<li class="active"><a href="javascript:;"><?php echo isset($help)?$this->lang->line('edit'):$this->lang->line('add') ?></a></li>
</ul>
<form class="form-inline deal-from container-fluid no-padding" id="help-form">
	<input type="hidden" name="id" value="<?php echo isset($help['id'])?$help['id']:0 ?>">
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('category') ?></label>
		<div class="form-group">
			<select name="type" class="form-control">
		  		<option value=""><?php echo $this->lang->line('category') ?></option>
		  		<?php foreach($types as $k=>$v): ?>
		  		<option value="<?php echo $k?>"><?php echo $v[$this->session->admin_language] ?></option>
		  		<?php endforeach; ?>
		  	</select>
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('cn_title') ?></label>
		<div class="form-group">
			<input type="text" name="title" class="form-control" value="<?php echo isset($help['title'])?$help['title']:''?>" style="width: 600px">
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('en_title') ?></label>
		<div class="form-group">
			<input type="text" name="en_title" class="form-control" value="<?php echo isset($help['en_title'])?$help['en_title']:''?>" style="width: 600px">
		</div>
	</div>
	
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('cn_content') ?></label>
		<div class="form-group" >
			<textarea id="editor" name="content" style="width:800px; height:200px;"><?php echo isset($help['content'])?$help['content']:'' ?></textarea>
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('en_content') ?></label>
		<div class="form-group" >
			<textarea id="en_content" name="en_content" style="width:800px; height:200px;"><?php echo isset($help['en_content'])?$help['en_content']:'' ?></textarea>
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('sort') ?></label>
		<div class="form-group" >
			<input type="text" name="sort" class="form-control" value="<?php echo isset($help['sort'])?$help['sort']:'0'?>" style="width: 100px">
		</div>
	</div>
	<div class="mt-20">
		<label for=""><?php echo $this->lang->line('status') ?></label>
		<div class="form-group" >
			<input type="radio" name="status" value="1" checked> <?php echo $this->lang->line('show') ?>
			<input type="radio" name="status" value="0" <?php isset($help['status'])&&$help['status']==0?'checked':'' ?>> <?php echo $this->lang->line('hide') ?>
		</div>
	</div>

	<div style="padding-left:110px" class="mt-20">
      <a href="javascript:;" class="btn btn-primary save"><?php echo $this->lang->line('save') ?></a>
      <a href="<?php echo $back_url ?>" class="btn btn-default cancel"><?php echo $this->lang->line('cancel') ?></a>
    </div>

	
</form>
</div>


<?php 
$js_array = array(
	'/assets/umeditor/third-party/template.min.js',
	'/assets/umeditor/umeditor.config.js',
	'/assets/umeditor/umeditor.js',
	'/assets/umeditor/lang/zh-cn/zh-cn.js'
	);
$this->load->view('admin/layout/footer',array('js'=>$js_array));
?>
<script type="text/javascript">
	var ue = UM.getEditor('editor');
	var ue2 = UM.getEditor('en_content');

	$('.save').click(function(event) {
		if(!$('select[name=type]').val()){
			alert('<?php echo $this->lang->line('submit_error_type') ?>');
			return;
		}
		if(!$('input[name=title]').val()){
			alert('<?php echo $this->lang->line('submit_error_cn_title') ?>');
			return;
		}
		if(!$('input[name=en_title]').val()){
			alert('<?php echo $this->lang->line('submit_error_en_title') ?>');
			return;
		}
		if(!ue.getContent()){
			alert('<?php echo $this->lang->line('submit_error_cn_content') ?>');
			return;
		}
		if(!ue2.getContent()){
			alert('<?php echo $this->lang->line('submit_error_en_content') ?>');
			return;
		}

		Toast.loading();
		$.post('/admin/help/save', $('#help-form').serialize(), function(data, textStatus, xhr) {
			Toast.destory();
			var json = $.parseJSON(data);
			if(json.code == 1){
				alert('<?php echo $this->lang->line('submit_error') ?>');
				return;
			}
			if(json.code == 2){
				alert('<?php echo $this->lang->line('submit_error_input') ?>');
				return;
			}
			Toast.success('<?php echo $this->lang->line('submit_success') ?>',function(){
				window.location = '<?php echo $back_url ?>#tr-'+json.help_id;
			})

		});
	});
</script>